//
// phpGetLongLat(theAddress)
//
// Get geocoding information from Google Maps
//
// Returns:
//      Status (1=good, 0=error)
//      longitude (blank on error)
//      latitude (blank on error)
//      precision (blank on error)
//
Let (
   [
      $theAddress = theAddress;

      phpCode = "¶
                 error_reporting(0); //E_ALL & ~E_NOTICE);¶
                 ¶
                 $theAddress = fm_evaluate('$theAddress');¶
                 $encodedAddress = urlencode($theAddress);¶
                 ¶
                 // Get your free key here: http://www.google.com/apis/maps/signup.html
                 $apiKey = 'ABQIAAAAmZQlaqMq0SG8cZOqMVM1JBRVMHVvXaDQkbHRgS_c55wKplVHbhS-fJPIU5O8O0jm2eZR3a7SmgFyeA';¶
                 ¶
                 // csv returns N lines of comma separated data¶
                 $url = 'http://maps.google.com/maps/geo?q=' . $encodedAddress . '&output=csv&key=' . $apiKey;¶
                 ¶
                 $ch = curl_init();¶
                 curl_setopt($ch, CURLOPT_URL, $url);¶
                 curl_setopt($ch, CURLOPT_HEADER,0);¶
                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);¶
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);¶
                 $addressData = curl_exec($ch);¶
                 curl_close($ch);¶
                 ¶
                 if (strstr($addressData,'200'))¶
                 {¶
                    $addressData = explode(',', $addressData);¶
                    ¶
                    $status    = $addressData[0];¶
                    $precision = $addressData[1];¶
                    $latitude  = $addressData[2];¶
                    $longitude = $addressData[3];¶
                    ¶
                    echo '1' . \"\r\" . $longitude . \"\r\" . $latitude . \"\r\" . $precision;¶
                 }¶
                 else¶
                 {¶
                    echo '0' . \"\r\r\r\";¶
                 }¶
                "
   ];
   PHP_Execute(phpCode)
)
